
public class Threadd2 {

    public static void main(String[] args) {
        
        System.out.println("==================== method-1 =====================");

        // -1 method
        Thread t = new MyThread();
        t.start(); // thread runn.
        try{
        Thread.sleep(10); // 暂停1毫秒
        t.interrupt(); // 中断t线程
        t.join(); // 等待t线程结束
        }catch(InterruptedException e){}
        System.out.println("main run end.");


        // System.out.println("==================== method-2 - runnable ===================");
        Thread t2 = new Thread(new Runna());
        t2.start();
        try{
            Thread.sleep(10);
            Runna.running = false;
            t2.join();
        }catch(InterruptedException e){}    
        System.out.println("main end-2 runnable.");


        // System.out.println("==================== method-3 - ()->{} ===================");
        // Thread t3 = new Thread(()->{
        //     System.out.println("thread run in method-3");
        // });
        // t3.start();
        
    }

}




class MyThread extends  Thread {

    @Override
    public void run(){
        int n = 0;
        while(! isInterrupted()){
            n++;
            System.out.println(n +" thread run method-1");
        }    
    }
}


//runnable
class Runna implements Runnable {
    public static volatile boolean running = true;  // share param 
    
    @Override
    public void run(){
        while(running){
            System.out.println("run in Runable -2 method.");
        }     
    }
}